<?php
$web_url = ABSURL."/order_confirm.php?d=cash|";
$payment=array(
	'rm'            => '2',// Return method = POST
	'cmd'           => '_xclick',
	'business'      => 'brian_1316425952_per@intrasia.com',
	'currency_code' => 'HKD',
	'return'        => $web_url.'return',//支付成功返回页面
	'cancel_return' => $web_url.'cancel',//取消订单页面
	'notify_url'    => $web_url.'notify',//支付处理页面
	'custom'        =>'IAWMS',//商户名称
);
/**
 * paypal接口类
 */
class Cash{

    public $lastError; //Holds the last error encountered

    public $logIpn;//Do we need to log IPN results ?

    public $ipnLogFile;//File to log IPN results

    public $ipnResponse;//Payment gateway IPN response

    public $testMode;//Are we in test mode ?

    public $fields = array();//Field array to submit to gateway

    public $ipnData = array();//IPN post values as array

    public $gatewayUrl;//Payment gateway URL

	public $furl = "/index.php";
	public $surl = "/index.php";

    public function addField($field, $value){
        $this->fields["$field"] = $value;
    }

    /**
    * 生成支付代码
    * @param   array   $order      订单信息
    * @param   array   $payment    支付方式信息
    */
   function GetCode($order,$payment){

       // $this->prepareSubmit();
		$str ='';
       /* $str.="<html>\n";
		$str.="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
        $str.="<head><title>处理支付...</title></head>\n";
        $str.="<body onLoad=\"document.forms['gateway_form'].submit();\">\n";
        $str.="<form method=\"POST\" name=\"gateway_form\" ";
        $str.="action=\"" . $this->gatewayUrl . "\">\n";*/
		
		/*$str.=$this->gatewayUrl;
		$i=0;
        foreach ($payment as $name => $value){
			if($i){
				 $str.='&'.$name.'='.$value;
			}else{
				 $str.='?'.$name.'='.$value;
			}
            $i++;
        }
		foreach ($order as $name => $value){
            if($i){
				 $str.='&'.$name.'='.$value;
			}else{
				 $str.='?'.$name.'='.$value;
			}
            $i++;
        }*/
		$str.= $payment['return'];
       // echo "</form>\n";
        //echo "</body></html>\n";
    	return "window.location.href='".$str."';";
	}

   
	public function __construct(){
        
	}

	/*开启测试paypal*/
    public function enableTestMode(){
		
    }


	public function getIpn(){
		return $this->text_ipn;
	}

    /*支付处理页面*/
	public function notify($flag=false){//异步调用该方法
		return true;
	}

	/*
	*支付返回处理
	*@param $base 网站url根路劲
	*@param $s 成功提示信息
	*@param $f 失败提示信息
	*@return Array
	*/
	function return_url($base,$s,$f){
		if($this->notify(true)){//开启测试
			$url = "window.location.href='".$base.$this->surl."';";
			$info ="succeed";
			$msg = '你选择了Cash支付方式,请带上现金去你选择的门市点,跟工作人员现场交易,谢谢合作。';
		}else{
			$url = "window.location.href='".$base.$this->furl."';";
			$info ="error";
			$msg = $f;
		}
		return array("url"=>$url,"msg"=>$msg,"info"=>$info);
	}

	/*处理订单成功*/
    function success_db($orderNo){
		return $orderNo;
    }

	/*处理订单失败*/
    function failure_db($orderNo){
       return $orderNo;
    }

	function setReturnUrl($s,$f){
		$this->surl = $s;
		$this->furl = $f;
	}
}
?>
